/* -----------------------------------------------------------------------------
 * PROJECT    : lwf_mockservice
 * FILE       : MockLookupService.java
 *
 * HISTORY:
 * Date          Author                        Description
 * ----------------------------------------------------------------------------- 
 * Feb 28, 2011  mycodetalks			       Created
 */
package net.lwf.user.fake.service;

import java.util.HashMap;
import java.util.Map;

import net.lwf.jaxb.service.JaxbService;
import net.lwf.user.fake.jaxb.User;
import net.lwf.user.fake.jaxb.Users;

public class MockUserService extends JaxbService {
	
	private static final String CONTEXT_PATH = "net.lwf.user.fake.jaxb";
	private String xmlFileName = "users.xml";

	private static Map<String, User> users;
	
	public User getUser(String userId, String password) {
		User user = null;
		if(users == null) {
			this.init();
		}
		if(users.containsKey(userId)) {
			user = users.get(userId);
		}
		return user;
	}
	
	@Override
	public String getContextPath() {
		return CONTEXT_PATH;
	}

	@Override
	public String getXmlFileName() {
		return xmlFileName;
	}
	
	private void init() {
		users = new HashMap<String, User>();
		Users userdata = (Users) loadedXmlData();
		for(User user: userdata.getUser()) {
			users.put(user.getUserId(), user);
		}
	}
	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		MockUserService service = new MockUserService();
		User user = service.getUser("teja-1", "BXV9mJ1bFq+7POUgsysIJOUV0HBOU5Zj");
		System.out.println("========> First Name: " + user.getFirstName() + "; Last Name: " + user.getLastName());
	}

}
